<?php

namespace app\admin\controller;
use app\admin\model\LogModel;
use think\Db;
use com\IpLocation;
 
class AccountLog extends Base
{

    /**
     *
     * [operate_log 操作日志]
     * @return [type] [description]
     * @author [田建龙] [864491238@qq.com]
     */
    public function index()
    {

        $key = input('key');
        $c = input('c');
        $add_time = input('add_time');
        $account_type = input('account_type');
        $s_id = input('s_id');
        $map = [];
        if($key&&$key!==""){
            $map['m.nickname'] = ['like',"%" . $key . "%"];
        }
        if($c&&$c!==""){
            $map['c.order_sn'] =  ['like',"%" . $c . "%"];
        }
        if( $account_type && $account_type!=="" ) $map['c.account_type']  =  $account_type;


        if($add_time&&$add_time!=="")
        {
            $tt = explode('~',$add_time);
            //dump($add_time);
            $map['c.change_time'] = ['between',[strtotime(trim($tt[0])),strtotime(trim($tt[1]).' 23:59:59')]];
        }

        $Nowpage = input('get.page') ? input('get.page'):1;
        $limits = config('list_rows');// 获取总条数
        $mm = $count = Db::name('account_log')->alias('c')->join('think_member m','c.uid = m.id','left')->join('think_order o','c.order_id = o.id','left')->where($map)->sum('user_money');//计算总页面
        $count = Db::name('account_log')->alias('c')->join('think_member m','c.uid = m.id','left')->join('think_order o','c.order_id = o.id','left')->where($map)->count();//计算总页面
        $allpage = intval(ceil($count / $limits));
        $lists = Db::name('account_log')->alias('c')->field('c.*,m.nickname')->join('think_member m','c.uid = m.id','left')->join('think_order o','c.order_id = o.id','left')->where($map)->page($Nowpage, $limits)->order('c.change_time desc')->select();

        if($lists){
            foreach ($lists as $k=>$v){
                $lists[$k]['change_time'] = date('Y-m-d H:i:s',$v['change_time']);
            }
        }

        $this->assign('Nowpage', $Nowpage); //当前页
        $this->assign('allpage', $allpage); //总页数 
        $this->assign('count', $count);
        $this->assign('val', $key);
        $this->assign('s_id', $s_id);
        $this->assign('c', $c);
        $this->assign('add_time', $add_time);
        $this->assign('account_type', $account_type);
        $this->assign('mm', $mm);
        //获取配送点

        if(input('get.page')){
            return json($lists);
        }
        return $this->fetch();
    }

}